Imports System.IO

''' <summary>
''' Searches specified directory for installed Daz3D products
''' </summary>
''' <remarks></remarks>
Public Class InstalledDaz3DProducts
    Inherits InstalledProductsBase

    Public Shadows Event ProductFound(ByVal productCode As String)

    Private Const Runtime As String = "runtime"

    Private Const ContentExtension As String = "*.txt"

    Private Const StandardDaz3DContentListLocation As String = "\ReadMe's\ProductLists"

    Private Const ContentListsNotFound As String = "There does not seem to be the standard Daz3D content list directory present (\ReadMe's\ProductLists)."

    ''' <summary>
    ''' Scans content installed at specified location for installed products using standard poser file formats
    ''' </summary>
    ''' <param name="runtimeLocation">Path to start scanning</param>
    ''' <remarks></remarks>
    Public Overrides Sub Scan(ByVal runtimeLocation As String)

        Dim dir As DirectoryInfo = New DirectoryInfo(runtimeLocation)
        If dir.Exists Then
            If dir.Name.ToLower = Runtime Then

            End If
        End If

    End Sub

    ''' <summary>
    ''' Scans for installed content using the Content List files isntalled by Daz3D products
    ''' </summary>
    ''' <param name="runtimeLocation">Path to start scanning</param>
    ''' <remarks>The location that is searched is \ReadMe's\ProductLists under the specified path to start scanning.</remarks>
    Public Sub ScanByContentList(ByVal runtimeLocation As String)

        Dim productCode As String = ""

        Dim dir As DirectoryInfo = New DirectoryInfo(runtimeLocation & StandardDaz3DContentListLocation)

        Dim pcta As New ProductContentTableAdapters.ContentTableAdapter

        If dir.Exists Then

            For Each file As FileInfo In dir.GetFiles(ContentExtension)

                productCode = pcta.GetProductCodeForContentFileName(file.Name)
                If Not productCode Is Nothing Then
                    If Not productCode Is System.DBNull.Value Then
                        If Not _installedProducts.ContainsKey(productCode) Then
                            _installedProducts.Add(productCode, _
                                                   New InstalledProduct(productCode, _
                                                       runtimeLocation))
                            RaiseEvent ProductFound(productCode)
                        End If
                    End If
                End If
            Next

        Else
            MsgBox(ContentListsNotFound)
        End If

    End Sub

End Class
